<?php
/**
 * Created by PhpStorm.
 * User: chendongliang
 * Date: 19-5-7
 * Time: 下午9:47
 */

namespace framework\Swoole\Server;

class Http
{
    protected $sw;
    protected $port;

    public function __construct($host, $port, $ssl = false)
    {
        $this->port = $port;

        $sw = new \swoole_http_server($host, $port);

        var_dump($sw);
        $sw->on('start', function($server){
            echo " from run http server is started at http://127.0.0.1:" . $this->port . "\n";

        });

        //$this->sw->onStart();
    }

    public function run()
    {
        //var_dump($this->sw);

//        $this->sw->on('start', array($this, 'onMasterStart'));
//        $this->sw->on('Shutdown', array($this, 'onMasterStop'));
//        $this->sw->on('ManagerStop', array($this, 'onManagerStop'));
//        $this->sw->on('WorkerStart', array($this, 'onWorkerStart'));
//        $this->sw->on('request', array($this, 'onRequest'));
    }


    public function onMasterStart()
    {
        echo "http server is started at http://127.0.0.1:" . $this->port . "\n";
    }

    public function onMasterStop()
    {
        echo "http server is stop \n";
    }


    public function onManagerStop()
    {

    }


    public function onWorkerStart()
    {

    }

    public function onRequest()
    {
        echo "request";
    }

}